<?php

use App\Http\Controllers\ChatController;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\QyWechatController;
use App\Http\Controllers\QyWebhookController;
use App\Http\Controllers\DataBaseController;
use App\Http\Controllers\TestController;
use App\Http\Controllers\Test1Controller;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return abort(403, '抱歉，你没有权限访问！');
});

Route::get('test', [TestController::class, 'test']);
Route::prefix('chong')->group(function () {
    Route::post('/', [QyWebhookController::class, 'git']);
});

Route::prefix('chatroom')->group(function () {
    Route::get('/', [ChatController::class, 'chatroom'])->name('chatroom');
    Route::get('/list', [ChatController::class, 'chatList']);
    Route::get('/download', [ChatController::class, 'downloadWxRes']);
});

Route::prefix('webhooks')->group(function () {
    Route::post('/git', [QyWebhookController::class, 'git']);
});

Route::prefix('data')->group(function () {
    Route::get('/index', [DataBaseController::class, 'index']);
    Route::any('/patient/del', [DataBaseController::class, 'delPatient']);
    Route::any('/doctor/del', [DataBaseController::class, 'delDoctor']);
    Route::get('/package/list', [DataBaseController::class, 'getPackages']);
    Route::any('/package/del', [DataBaseController::class, 'delPackage']);
    Route::get('/flup/list', [DataBaseController::class, 'getFlup']);
    Route::any('/flup/del', [DataBaseController::class, 'delFlup']);
    Route::get('/signin/list', [DataBaseController::class, 'getSignin']);
    Route::any('/signin/del', [DataBaseController::class, 'delSignin']);
});

$qy = Request::query('qy', 'default');
\Illuminate\Support\Facades\Log::info($qy);
Route::group(['middleware' => ['web', 'wechat.oauth:'.$qy.',snsapi_userinfo,work']], function () {
    Route::get('/user', [QyWechatController::class, 'index']);
    Route::get('/customers/{chatId}', [QyWechatController::class, 'customers']);
});
